package com.myproject.filmrecommendationsys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.myproject.filmrecommendationsys.domain.Favorite;
import com.myproject.filmrecommendationsys.service.IFavoriteService;
import com.myproject.filmrecommendationsys.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 收藏Controller
 */
@RestController
@RequestMapping("/favorite")
@Api(tags="收藏管理")
public class FavoriteController
{
    @Autowired
    private IFavoriteService favoriteService;

    /**
     * 查询收藏列表
     */

    @GetMapping("/list")
    @ApiOperation("查询收藏列表")
    public AjaxResult list(Favorite favorite)
    {
        return AjaxResult.success(favoriteService.selectFavoriteList(favorite));
    }

    /**
     * 获取收藏详细信息
     */

    @GetMapping(value = "/{id}")
    @ApiOperation("获取收藏详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(favoriteService.selectFavoriteById(id));
    }

    /**
     * 新增收藏
     */

    @PostMapping("/add")
    @ApiOperation("新增收藏")
    public AjaxResult add(@RequestBody Favorite favorite)
    {
        return AjaxResult.success(favoriteService.insertFavorite(favorite));
    }

    /**
     * 修改收藏
     */
    @PutMapping("/update")
    @ApiOperation("修改收藏")
    public AjaxResult edit(@RequestBody Favorite favorite)
    {
        return AjaxResult.success(favoriteService.updateFavorite(favorite));
    }

    /**
     * 删除收藏
     */
	@DeleteMapping("/{ids}")
    @ApiOperation("删除收藏")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return AjaxResult.success(favoriteService.deleteFavoriteByIds(ids));
    }
}
